const { dialog } = require('electron');

// 文件选择对话框
const openFileDialogFn = async (event, options) => {
  const result = await dialog.showOpenDialog(event.sender.getOwnerBrowserWindow(), {
    properties: ['openFile'],
    ...options
  });
  if (result.canceled) {
    return [];
  }
  return result.filePaths;
};

// 目录选择对话框
const openDirectoryDialogFn = async (event, options) => {
  const result = await dialog.showOpenDialog(event.sender.getOwnerBrowserWindow(), {
    properties: ['openDirectory'],
    ...options
  });
  if (result.canceled) {
    return [];
  }
  return result.filePaths;
};

// 保存文件对话框
const saveFileDialogFn = async (event, options) => {
  const result = await dialog.showSaveDialog(event.sender.getOwnerBrowserWindow(), options);
  if (result.canceled) {
    return null;
  }
  return result.filePath;
};

module.exports = {
  openFileDialogFn,
  openDirectoryDialogFn,
  saveFileDialogFn
};
